﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace InventoryManager
{
    public delegate void FormChangedHandler(string changingForm, object[] param);
    public delegate void EditFormClosedHandler(int recordType);
    
    public partial class MainForm : Form
    {
        private const int WIDTH = 800;
        private const int HEIGHT = 430;

        private const string ORDERFORM_SELECTION = "ORDERFORM_SELECTION";
        private const string ORDERFORM_VIEW_1 = "ORDERFORM_VIEW_1";
        private const string ORDERFORM_VIEW_2 = "ORDERFORM_VIEW_2";
        private const string ORDERFORM_ADD_1 = "ORDERFORM_ADD_1";
        private const string ORDERFORM_ADD_2 = "ORDERFORM_ADD_2";

        private const string REQUISITION_SELECTION = "REQUISITION_SELECTION";
        private const string REQUISITION_VIEW_1 = "REQUISITION_VIEW_1";
        private const string REQUISITION_VIEW_2 = "REQUISITION_VIEW_2";
        private const string REQUISITION_ADD_1 = "REQUISITION_ADD_1";
        private const string REQUISITION_ADD_2 = "REQUISITION_ADD_2";

        private const string INVOICE_SELECTION = "INVOICE_SELECTION";
        private const string INVOICE_VIEW_1 = "INVOICE_VIEW_1";
        private const string INVOICE_VIEW_2 = "INVOICE_VIEW_2";
        private const string INVOICE_ADD_1 = "INVOICE_ADD_1";
        private const string INVOICE_ADD_2 = "INVOICE_ADD_2";
        private const string INVOICE_ADD_3 = "INVOICE_ADD_3";

        private int _currentMenu;
        private int _linkDepth;

        private const int LEFT_MARGIN_LINK = 13;
        private const int RIGHT_MARGIN_LINK = 6;

        private Color FirstMenuColor;
        private Color SecondMenuColor;
        private Color ThirdMenuColor;
        private Color ForthMenuColor;

        // 1st color = 255, 96, 0
        // 2nd color = 37, 202, 53
        // 3rd color = 51, 141, 225
        // 4th color = 255, 0, 42

        // L(i) (LEFT_MARGIN_LINK) >> (RIGHT_MARGIN_LINK) L(i+1)

        private const string CONNECTION_STRING = "Database=inventory;" + "Data Source=127.0.0.1;" +
                    "User Id=root;Password=;Character Set=utf8;" + 
                    "Connection Timeout=20";

        private Control _displayingControl;

        private Control _orderFormDisplayingControl;
        private Control _requisitionFromDisplayingControl;
        private Control _invoiceFormDisplayingControl;
        private Control _merchandiseSummaryDisplayingControl;

        private string[] _orderFormLinkCollection;
        private string[] _requisitionFormLinkCollection;
        private string[] _invoiceFormLinkCollection;
        private string[] _merchandiseSummaryLinkCollection;

        public MainForm()
        {
            InitializeComponent();

            FirstMenuColor = Color.FromArgb(255, 96, 0);
            SecondMenuColor = Color.FromArgb(37, 202, 53);
            ThirdMenuColor = Color.FromArgb(51, 141, 225);
            ForthMenuColor = Color.FromArgb(255, 0, 42);

            _currentMenu = 0;
            _linkDepth = 0;

            _displayingControl = null;

            _orderFormDisplayingControl = null;
            _requisitionFromDisplayingControl = null;
            _invoiceFormDisplayingControl = null;
            _merchandiseSummaryDisplayingControl = null;

            _orderFormLinkCollection = new string[3];
            _requisitionFormLinkCollection = new string[3];
            _invoiceFormLinkCollection = new string[3];
            _merchandiseSummaryLinkCollection = new string[3];

            DisplayAreaSplitContainer.Visible = false;
        }

        private void OrderFormButton_Click(object sender, EventArgs e)
        {
            DisplayAreaSplitContainer.Visible = true;
            this.BackgroundImage = null;
            LoadOrderFormByTab();
        }

        private void RequisitionFormButton_Click(object sender, EventArgs e)
        {
            DisplayAreaSplitContainer.Visible = true;
            this.BackgroundImage = null;
            LoadRequisitionFormByTab();
        }

        private void InvoiceFormButton_Click(object sender, EventArgs e)
        {
            DisplayAreaSplitContainer.Visible = true;
            this.BackgroundImage = null;
            LoadInvoiceFormByTab();
        }

        private void MerchandiseSummaryFormButton_Click(object sender, EventArgs e)
        {
            DisplayAreaSplitContainer.Visible = true;
            this.BackgroundImage = null;
            LoadMerchandiseSummaryByTab();
        }

        private void LoadOrderFormByTab()
        {
            if (_currentMenu == 1)
                return;

            if (_displayingControl != null)
                this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);

            if (_orderFormDisplayingControl == null)
            {
                OrderFormSelectionPageUserControl newPage = new OrderFormSelectionPageUserControl(WIDTH, HEIGHT);
                newPage.FormChangedEvent += new FormChangedHandler(FormChangedEvent);
                _orderFormDisplayingControl = newPage;
                _orderFormLinkCollection[0] = "ใบสั่งสินค้า";
                _orderFormLinkCollection[1] = null;
                _orderFormLinkCollection[2] = null;
            }

            _displayingControl = _orderFormDisplayingControl;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetWhiteColorToAllButtons();
            this.OrderFormButton.BackColor = Color.FromArgb(255, 192, 128);

            SetTextAndColorToNavigationBar
                (1, _orderFormLinkCollection[0], _orderFormLinkCollection[1], _orderFormLinkCollection[2]);
            _currentMenu = 1;
        }

        private void LoadOrderFormByLink()
        {
            if (_displayingControl != null)
                this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);

            _orderFormDisplayingControl = null;
            OrderFormSelectionPageUserControl newPage = new OrderFormSelectionPageUserControl(WIDTH, HEIGHT);
            newPage.FormChangedEvent += new FormChangedHandler(FormChangedEvent);
            _orderFormDisplayingControl = newPage;
            _orderFormLinkCollection[0] = "ใบสั่งสินค้า";
            _orderFormLinkCollection[1] = null;
            _orderFormLinkCollection[2] = null;

            _displayingControl = _orderFormDisplayingControl;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetWhiteColorToAllButtons();
            this.OrderFormButton.BackColor = Color.FromArgb(255, 192, 128);

            SetTextAndColorToNavigationBar
                (1, _orderFormLinkCollection[0], _orderFormLinkCollection[1], _orderFormLinkCollection[2]);
            _currentMenu = 1;
        }

        private void LoadViewOrderForm_1()
        {
            this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);
            _orderFormDisplayingControl = null;
            ViewOrderForm_1_UserControl newPage = new ViewOrderForm_1_UserControl(CONNECTION_STRING, WIDTH, HEIGHT);
            newPage.FormChangedEvent+=new FormChangedHandler(FormChangedEvent);
            _orderFormDisplayingControl = newPage;
            _orderFormLinkCollection[0] = "ใบสั่งสินค้า";
            _orderFormLinkCollection[1] = "ดูรายการ";
            _orderFormLinkCollection[2] = null;
            _displayingControl = _orderFormDisplayingControl;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetTextAndColorToNavigationBar
                (1, _orderFormLinkCollection[0], _orderFormLinkCollection[1], _orderFormLinkCollection[2]);
        }

        private void LoadViewOrderForm_2(object[] param)
        {
            this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);
            _orderFormDisplayingControl = null;
            ViewOrderForm_2_UserControl newPage = new ViewOrderForm_2_UserControl(CONNECTION_STRING, param, WIDTH, HEIGHT);
            newPage.FormChangedEvent+=new FormChangedHandler(FormChangedEvent);
            _orderFormDisplayingControl = newPage;
            _orderFormLinkCollection[0] = "ใบสั่งสินค้า";
            _orderFormLinkCollection[1] = "ดูรายการ";
            _orderFormLinkCollection[2] = "ผลลัพธ์";
            _displayingControl = _orderFormDisplayingControl;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetTextAndColorToNavigationBar
                (1, _orderFormLinkCollection[0], _orderFormLinkCollection[1], _orderFormLinkCollection[2]);
        }

        private void LoadAddOrderForm_1()
        {
            this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);
            _orderFormDisplayingControl = null;
            AddOrderForm_1_userControl newPage = new AddOrderForm_1_userControl(CONNECTION_STRING, WIDTH, HEIGHT);
            newPage.FormChangedEvent += new FormChangedHandler(FormChangedEvent);
            _orderFormDisplayingControl = newPage;
            _orderFormLinkCollection[0] = "ใบสั่งสินค้า";
            _orderFormLinkCollection[1] = "สร้างรายการใหม่";
            _orderFormLinkCollection[2] = null;
            _displayingControl = _orderFormDisplayingControl;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetTextAndColorToNavigationBar
                (1, _orderFormLinkCollection[0], _orderFormLinkCollection[1], _orderFormLinkCollection[2]);
        }

        private void LoadRequisitionFormByTab()
        {
            if (_currentMenu == 2)
                return;

            if (_displayingControl != null)
                this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);

            if (_requisitionFromDisplayingControl == null)
            {
                RequisitionFormSelectionPageUserControl newPage = new RequisitionFormSelectionPageUserControl(WIDTH, HEIGHT);
                newPage.FormChangedEvent += new FormChangedHandler(FormChangedEvent);
                _requisitionFromDisplayingControl = newPage;
                _requisitionFormLinkCollection[0] = "ใบเบิกสินค้าชั่วคราว";
                _requisitionFormLinkCollection[1] = null;
                _requisitionFormLinkCollection[2] = null;
            }

            _displayingControl = _requisitionFromDisplayingControl;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetWhiteColorToAllButtons();
            this.RequisitionFormButton.BackColor = Color.FromArgb(128, 255, 128);

            SetTextAndColorToNavigationBar
                (2, _requisitionFormLinkCollection[0], _requisitionFormLinkCollection[1], _requisitionFormLinkCollection[2]);
            _currentMenu = 2;
        }

        private void LoadRequisitionFormByLink()
        {
            if (_displayingControl != null)
                this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);

            _requisitionFromDisplayingControl = null;
            RequisitionFormSelectionPageUserControl newPage = new RequisitionFormSelectionPageUserControl(WIDTH, HEIGHT);
            newPage.FormChangedEvent += new FormChangedHandler(FormChangedEvent);
            _requisitionFromDisplayingControl = newPage;
            _requisitionFormLinkCollection[0] = "ใบเบิกสินค้าชั่วคราว";
            _requisitionFormLinkCollection[1] = null;
            _requisitionFormLinkCollection[2] = null;

            _displayingControl = _requisitionFromDisplayingControl;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetWhiteColorToAllButtons();
            this.RequisitionFormButton.BackColor = Color.FromArgb(128, 255, 128);

            SetTextAndColorToNavigationBar
                (2, _requisitionFormLinkCollection[0], _requisitionFormLinkCollection[1], _requisitionFormLinkCollection[2]);
            _currentMenu = 2;
        }

        private void LoadViewRequisitionForm_1()
        {
            this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);
            _requisitionFromDisplayingControl = null;
            ViewRequisitionForm_1_UserControl newPage = new ViewRequisitionForm_1_UserControl(CONNECTION_STRING, WIDTH, HEIGHT, false);
            newPage.FormChangedEvent += new FormChangedHandler(FormChangedEvent);
            _requisitionFromDisplayingControl = newPage;
            _requisitionFormLinkCollection[0] = "ใบเบิกสินค้าชั่วคราว";
            _requisitionFormLinkCollection[1] = "ดูรายการ";
            _requisitionFormLinkCollection[2] = null;
            _displayingControl = _requisitionFromDisplayingControl;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetTextAndColorToNavigationBar
                (2, _requisitionFormLinkCollection[0], _requisitionFormLinkCollection[1], _requisitionFormLinkCollection[2]);
        }

        private void LoadViewRequisitionForm_2(object[] param)
        {
            this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);
            _requisitionFromDisplayingControl = null;
            ViewRequisitionForm_2_UserControl newPage = new ViewRequisitionForm_2_UserControl(CONNECTION_STRING, param, WIDTH, HEIGHT, false);
            newPage.FormChangedEvent += new FormChangedHandler(FormChangedEvent);
            _requisitionFromDisplayingControl = newPage;
            _requisitionFormLinkCollection[0] = "ใบเบิกสินค้าชั่วคราว";
            _requisitionFormLinkCollection[1] = "ดูรายการ";
            _requisitionFormLinkCollection[2] = "ผลลัพธ์";
            _displayingControl = _requisitionFromDisplayingControl;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetTextAndColorToNavigationBar
                (2, _requisitionFormLinkCollection[0], _requisitionFormLinkCollection[1], _requisitionFormLinkCollection[2]);
        }

        private void LoadAddRequisitionForm_1()
        {
            this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);
            _requisitionFromDisplayingControl = null;
            AddRequisitionForm_1_UserControl newPage = new AddRequisitionForm_1_UserControl(CONNECTION_STRING, WIDTH, HEIGHT);
            newPage.FormChangedEvent += new FormChangedHandler(FormChangedEvent);
            _requisitionFromDisplayingControl = newPage;
            _requisitionFormLinkCollection[0] = "ใบเบิกสินค้าชั่วคราว";
            _requisitionFormLinkCollection[1] = "สร้างรายการใหม่";
            _requisitionFormLinkCollection[2] = null;
            _displayingControl = _requisitionFromDisplayingControl; ;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetTextAndColorToNavigationBar
                (2, _requisitionFormLinkCollection[0], _requisitionFormLinkCollection[1], _requisitionFormLinkCollection[2]);
        }

        private void LoadInvoiceFormByTab()
        {
            if (_currentMenu == 3)
                return;

            if (_displayingControl != null)
                this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);

            if (_invoiceFormDisplayingControl == null)
            {
                InvoiceFormSelectionPageUserControl newPage = new InvoiceFormSelectionPageUserControl(WIDTH, HEIGHT);
                newPage.FormChangedEvent += new FormChangedHandler(FormChangedEvent);
                _invoiceFormDisplayingControl = newPage;
                _invoiceFormLinkCollection[0] = "ใบกำกับภาษี/ใบส่งของ/ใบเสร็จรับเงิน";
                _invoiceFormLinkCollection[1] = null;
                _invoiceFormLinkCollection[2] = null;
            }

            _displayingControl = _invoiceFormDisplayingControl;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetWhiteColorToAllButtons();
            this.InvoiceFormButton.BackColor = Color.FromArgb(128, 255, 255);

            SetTextAndColorToNavigationBar
                (3, _invoiceFormLinkCollection[0], _invoiceFormLinkCollection[1], _invoiceFormLinkCollection[2]);
            _currentMenu = 3;
        }

        private void LoadInvoiceFormByLink()
        {
            if (_displayingControl != null)
                this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);

            _invoiceFormDisplayingControl = null;
            InvoiceFormSelectionPageUserControl newPage = new InvoiceFormSelectionPageUserControl(WIDTH, HEIGHT);
            newPage.FormChangedEvent += new FormChangedHandler(FormChangedEvent);
            _invoiceFormDisplayingControl = newPage;
            _invoiceFormLinkCollection[0] = "ใบกำกับภาษี/ใบส่งของ/ใบเสร็จรับเงิน";
            _invoiceFormLinkCollection[1] = null;
            _invoiceFormLinkCollection[2] = null;

            _displayingControl = _invoiceFormDisplayingControl;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetWhiteColorToAllButtons();
            this.InvoiceFormButton.BackColor = Color.FromArgb(128, 255, 255);

            SetTextAndColorToNavigationBar
                (3, _invoiceFormLinkCollection[0], _invoiceFormLinkCollection[1], _invoiceFormLinkCollection[2]);
            _currentMenu = 3;
        }

        private void LoadViewInvoiceForm_1()
        {
            this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);
            _invoiceFormDisplayingControl = null;
            ViewInvoiceForm_1_UserControl newPage = new ViewInvoiceForm_1_UserControl(CONNECTION_STRING, WIDTH, HEIGHT);
            newPage.FormChangedEvent += new FormChangedHandler(FormChangedEvent);
            _invoiceFormDisplayingControl = newPage;
            _invoiceFormLinkCollection[0] = "ใบกำกับภาษี/ใบส่งของ/ใบเสร็จรับเงิน";
            _invoiceFormLinkCollection[1] = "ดูรายการ";
            _invoiceFormLinkCollection[2] = null;
            _displayingControl = _invoiceFormDisplayingControl;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetTextAndColorToNavigationBar
                (3, _invoiceFormLinkCollection[0], _invoiceFormLinkCollection[1], _invoiceFormLinkCollection[2]);
        }

        private void LoadViewInvoiceForm_2(object[] param)
        {
            this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);
            _invoiceFormDisplayingControl = null;
            ViewInvoiceForm_2_UserControl newPage = new ViewInvoiceForm_2_UserControl(CONNECTION_STRING, param, WIDTH, HEIGHT);
            newPage.FormChangedEvent += new FormChangedHandler(FormChangedEvent);
            _invoiceFormDisplayingControl = newPage;
            _invoiceFormLinkCollection[0] = "ใบกำกับภาษี/ใบส่งของ/ใบเสร็จรับเงิน";
            _invoiceFormLinkCollection[1] = "ดูรายการ";
            _invoiceFormLinkCollection[2] = "ผลลัพธ์";
            _displayingControl = _invoiceFormDisplayingControl;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetTextAndColorToNavigationBar
                (3, _invoiceFormLinkCollection[0], _invoiceFormLinkCollection[1], _invoiceFormLinkCollection[2]);
        }

        private void LoadAddInvoiceForm_1()
        {
            this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);
            _invoiceFormDisplayingControl = null;
            ViewRequisitionForm_1_UserControl newPage = new ViewRequisitionForm_1_UserControl(CONNECTION_STRING, WIDTH, HEIGHT, true);
            newPage.FormChangedEvent += new FormChangedHandler(FormChangedEvent);
            _invoiceFormDisplayingControl = newPage;
            _invoiceFormLinkCollection[0] = "ใบกำกับภาษี/ใบส่งของ/ใบเสร็จรับเงิน";
            _invoiceFormLinkCollection[1] = "สร้างรายการใหม่";
            _invoiceFormLinkCollection[2] = null;
            _displayingControl = _invoiceFormDisplayingControl; ;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetTextAndColorToNavigationBar
                (3, _invoiceFormLinkCollection[0], _invoiceFormLinkCollection[1], _invoiceFormLinkCollection[2]);
        }

        private void LoadAddInvoiceForm_2(object[] param)
        {
            this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);
            _invoiceFormDisplayingControl = null;
            ViewRequisitionForm_2_UserControl newPage = new ViewRequisitionForm_2_UserControl(CONNECTION_STRING, param, WIDTH, HEIGHT, true);
            newPage.FormChangedEvent += new FormChangedHandler(FormChangedEvent);
            _invoiceFormDisplayingControl = newPage;
            _invoiceFormLinkCollection[0] = "ใบกำกับภาษี/ใบส่งของ/ใบเสร็จรับเงิน";
            _invoiceFormLinkCollection[1] = "สร้างรายการใหม่";
            _invoiceFormLinkCollection[2] = null;
            _displayingControl = _invoiceFormDisplayingControl; ;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetTextAndColorToNavigationBar
                (3, _invoiceFormLinkCollection[0], _invoiceFormLinkCollection[1], _invoiceFormLinkCollection[2]);
        }

        private void LoadAddInvoiceForm_3(object[] param)
        {
            this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);
            _invoiceFormDisplayingControl = null;
            AddInvoiceForm_3_UserControl newPage = new AddInvoiceForm_3_UserControl(CONNECTION_STRING, 
                WIDTH, HEIGHT, Int32.Parse((string)param[0]));
            newPage.FormChangedEvent += new FormChangedHandler(FormChangedEvent);
            _invoiceFormDisplayingControl = newPage;
            _invoiceFormLinkCollection[0] = "ใบกำกับภาษี/ใบส่งของ/ใบเสร็จรับเงิน";
            _invoiceFormLinkCollection[1] = "สร้างรายการใหม่";
            _invoiceFormLinkCollection[2] = null;
            _displayingControl = _invoiceFormDisplayingControl; ;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetWhiteColorToAllButtons();
            this.InvoiceFormButton.BackColor = Color.FromArgb(128, 255, 255);

            SetTextAndColorToNavigationBar
                (3, _invoiceFormLinkCollection[0], _invoiceFormLinkCollection[1], _invoiceFormLinkCollection[2]);
            _currentMenu = 3;
        }

        private void LoadMerchandiseSummaryByTab()
        {
            if (_currentMenu == 4)
                return;

            if (_displayingControl != null)
                this.DisplayAreaSplitContainer.Panel2.Controls.Remove(_displayingControl);

            if (_merchandiseSummaryDisplayingControl == null)
            {
                MerchandiseSummaryUserControl newPage = new MerchandiseSummaryUserControl(CONNECTION_STRING, WIDTH, HEIGHT);
                _merchandiseSummaryDisplayingControl = newPage;
                _merchandiseSummaryLinkCollection[0] = "รายงานสินค้าและวัตถุดิบ";
                _merchandiseSummaryLinkCollection[1] = null;
                _merchandiseSummaryLinkCollection[2] = null;
            }

            _displayingControl = _merchandiseSummaryDisplayingControl;
            this.DisplayAreaSplitContainer.Panel2.Controls.Add(_displayingControl);

            SetWhiteColorToAllButtons();
            this.MerchandiseSummaryFormButton.BackColor = Color.FromArgb(255, 128, 128);

            SetTextAndColorToNavigationBar
                (4, _merchandiseSummaryLinkCollection[0], _merchandiseSummaryLinkCollection[1], 
                _merchandiseSummaryLinkCollection[2]);
            _currentMenu = 4;
        }

        private void FormChangedEvent(string changingForm, object[] param)
        {
            switch (changingForm)
            {
                case ORDERFORM_SELECTION:
                    LoadOrderFormByLink();
                    break;
                case ORDERFORM_VIEW_1:
                    LoadViewOrderForm_1();
                    break;
                case ORDERFORM_VIEW_2:
                    LoadViewOrderForm_2(param);
                    break;
                case ORDERFORM_ADD_1:
                    LoadAddOrderForm_1();
                    break;
                case REQUISITION_SELECTION:
                    LoadRequisitionFormByLink();
                    break;
                case REQUISITION_VIEW_1:
                    LoadViewRequisitionForm_1();
                    break;
                case REQUISITION_VIEW_2:
                    LoadViewRequisitionForm_2(param);
                    break;
                case REQUISITION_ADD_1:
                    LoadAddRequisitionForm_1();
                    break;
                case INVOICE_SELECTION:
                    LoadInvoiceFormByLink();
                    break;
                case INVOICE_VIEW_1:
                    LoadViewInvoiceForm_1();
                    break;
                case INVOICE_VIEW_2:
                    LoadViewInvoiceForm_2(param);
                    break;
                case INVOICE_ADD_1:
                    LoadAddInvoiceForm_1();
                    break;
                case INVOICE_ADD_2:
                    LoadAddInvoiceForm_2(param);
                    break;
                case INVOICE_ADD_3:
                    LoadAddInvoiceForm_3(param);
                    break;
                default:
                    break;
            }
        }

        private void SetTextAndColorToNavigationBar(int menu, 
            string firstLinkName, string secondLinkName, string thirdLinkName)
        {
            BarPanel.Visible = true;
            FirstLinkLabel.Visible = false;
            SecondLinkLabel.Visible = false;
            ThirdLinkLabel.Visible = false;
            FirstSeparatorLabel.Visible = false;
            SecondSeparatorLabel.Visible = false;

            _linkDepth = 0;

            if (firstLinkName != null)
            {
                FirstLinkLabel.Text = firstLinkName;
                FirstLinkLabel.Visible = true;
                _linkDepth++;
            }
            else
                return;

            if (secondLinkName != null)
            {
                FirstSeparatorLabel.Location =
                    new Point(FirstLinkLabel.Location.X + FirstLinkLabel.Width + LEFT_MARGIN_LINK,
                        FirstSeparatorLabel.Location.Y);

                SecondLinkLabel.Location =
                    new Point(FirstSeparatorLabel.Location.X + FirstSeparatorLabel.Width + RIGHT_MARGIN_LINK,
                        SecondLinkLabel.Location.Y);

                FirstSeparatorLabel.Visible = true;
                SecondLinkLabel.Text = secondLinkName;
                SecondLinkLabel.Visible = true;
                _linkDepth++;
            }

            if (thirdLinkName != null)
            {
                SecondSeparatorLabel.Location =
                                   new Point(SecondLinkLabel.Location.X + SecondLinkLabel.Width + LEFT_MARGIN_LINK,
                                       SecondSeparatorLabel.Location.Y);

                ThirdLinkLabel.Location =
                    new Point(SecondSeparatorLabel.Location.X + SecondSeparatorLabel.Width + RIGHT_MARGIN_LINK,
                        ThirdLinkLabel.Location.Y);

                SecondSeparatorLabel.Visible = true;
                ThirdLinkLabel.Text = thirdLinkName;
                ThirdLinkLabel.Visible = true;
                _linkDepth++;
            }

            switch (menu)
            {
                case 1:
                    BarPanel.BackColor = FirstMenuColor;
                    FirstLinkLabel.LinkColor = FirstMenuColor;
                    SecondLinkLabel.LinkColor = FirstMenuColor;
                    ThirdLinkLabel.LinkColor = FirstMenuColor;
                    FirstSeparatorLabel.ForeColor = FirstMenuColor;
                    SecondSeparatorLabel.ForeColor = FirstMenuColor;
                    break;
                case 2:
                    BarPanel.BackColor = SecondMenuColor;
                    FirstLinkLabel.LinkColor = SecondMenuColor;
                    SecondLinkLabel.LinkColor = SecondMenuColor;
                    ThirdLinkLabel.LinkColor = SecondMenuColor;
                    FirstSeparatorLabel.ForeColor = SecondMenuColor;
                    SecondSeparatorLabel.ForeColor = SecondMenuColor;
                    break;
                case 3:
                    BarPanel.BackColor = ThirdMenuColor;
                    FirstLinkLabel.LinkColor = ThirdMenuColor;
                    SecondLinkLabel.LinkColor = ThirdMenuColor;
                    ThirdLinkLabel.LinkColor = ThirdMenuColor;
                    FirstSeparatorLabel.ForeColor = ThirdMenuColor;
                    SecondSeparatorLabel.ForeColor = ThirdMenuColor;
                    break;
                case 4:
                    BarPanel.BackColor = ForthMenuColor;
                    FirstLinkLabel.LinkColor = ForthMenuColor;
                    SecondLinkLabel.LinkColor = ForthMenuColor;
                    ThirdLinkLabel.LinkColor = ForthMenuColor;
                    FirstSeparatorLabel.ForeColor = ForthMenuColor;
                    SecondSeparatorLabel.ForeColor = ForthMenuColor;
                    break;
                default:
                    break;
            }
        }

        private void SetWhiteColorToAllButtons()
        {
            this.OrderFormButton.BackColor = Color.White;
            this.RequisitionFormButton.BackColor = Color.White;
            this.InvoiceFormButton.BackColor = Color.White;
            this.MerchandiseSummaryFormButton.BackColor = Color.White;
        }

        private void FirstLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (_linkDepth == 1)
                return;

            switch(_currentMenu)
            {
                case 1:
                    LoadOrderFormByLink();
                    break;
                case 2:
                    LoadRequisitionFormByLink();
                    break;
                case 3:
                    LoadInvoiceFormByLink();
                    break;
                default:
                    break;
            }
        }

        private void SecondLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (_linkDepth == 2)
                return;
            else if (_linkDepth == 3)
            {
                switch (_currentMenu)
                {
                    case 1:
                        LoadViewOrderForm_1();
                        break;
                    case 2:
                        LoadViewRequisitionForm_1();
                        break;
                    case 3:
                        LoadViewInvoiceForm_1();
                        break;
                    default:
                        break;
                }
            }
        }

        private void DatabaseEditorLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            (new DatabaseEditorForm(CONNECTION_STRING)).ShowDialog();
        }
    }
}
